package com.longxin.demoapp.experiments.experiment1.service.impl;

import android.app.Activity;
import android.view.View;
import android.widget.Checkable;
import android.widget.EditText;
import com.longxin.demoapp.R;
import com.longxin.demoapp.base.service.impl.IBaseServiceImpl;
import com.longxin.demoapp.experiments.experiment1.service.Experiment1Service;
import com.longxin.demoapp.utils.DialogUtil;

/**
 * @author Long
 * @version 1.0
 * @description:
 * @remarks:
 * @title ExperimentActivity1ServiceImpl
 * @date 2021/4/6 17:08
 */
public class Experiment1ServiceImpl extends IBaseServiceImpl implements Experiment1Service {

    public Experiment1ServiceImpl(Activity activity) {
        super(activity);
    }

    @Override
    public void comput(View v) {

        boolean man = true;
        double height, weight, own;
        try {
            height = Double.parseDouble(((EditText) activity.findViewById(R.id.experiment_1_main_edit_text_height)).getText().toString());
        } catch (Exception e) {
            DialogUtil.dialog(activity, "请输入正确的身高");
            return;
        }
        try {
            weight = Double.parseDouble(((EditText) activity.findViewById(R.id.experiment_1_main_edit_text_weight)).getText().toString());
        } catch (Exception e) {
            DialogUtil.dialog(activity, "请输入正确的体重");
            return;
        }

        if (((Checkable) activity.findViewById(R.id.experiment_1_main_radio_btn_male)).isChecked()) {
            own = 170 - (62 - weight) / 0.6;
        } else if (((Checkable) activity.findViewById(R.id.experiment_1_main_radio_btn_female)).isChecked()) {
            own = 158 - (52 - weight) / 0.5;
            man = false;
        } else {
            DialogUtil.dialog(activity, "请选择性别");
            return;
        }
        get(man, own, height);
    }

    @Override
    public void get(boolean man, double own, double height) {
        String msg = "您的体质";
        double p = 3;
        if (man) p = 5;
        if (height <= (own + p) && height >= (own - p)) {
            msg += "正常";
        }else if (height <= (own + p)) {
            msg += "偏胖";
        }else if (height >= (own - p)) {
            msg += "偏瘦";
        }
        DialogUtil.dialog(activity, msg);
    }
}
